import { create } from '../asyncActionCreator';

/**
 * 改变当前选项
 * @type {String}
 */
export const CHANGE_OPTION = 'change exam current option';

/**
 * 切换到 人/题次 视图
 * @type {String}
 */
export const PV_ACTIVE = 'active pv option';

/**
 * 切换到 人/题数 视图
 * @type {String}
 */
export const UV_ACTIVE = 'active uv option';

/**
 * 获取数据
 * @type {String}
 */
export const GET_DATA_REQUEST = 'request exam chart data';
export const GET_DATA_SUCCESS = 'request exam chart data success';
export const GET_DATA_FAILURE = 'request exam chart data failure';

/**
 * 改变当前时间颗粒度
 * @type {String}
 */
export const CHANGE_TIME_UNIT = 'change exam current time unit';


export const changeOption = (option) => ({
	type: CHANGE_OPTION,
	payload: {
		option
	}
});

export const changeTimeUnit = (option) => ({
	type: CHANGE_TIME_UNIT,
	payload: {
		option
	}
})

export const PVActive = () => ({
	type: PV_ACTIVE,
	payload: {}
});

export const UVActive = () => ({
	type: UV_ACTIVE,
	payload: {}
});

export const getDataRequest = (key) => ({
	type: GET_DATA_REQUEST,
	payload: {
		key
	}
});

export const getDataSuccess = (key, data) => ({
	type: GET_DATA_SUCCESS,
	payload: {
		key,
		data
	}
});

export const getDataFailure = (key, message) => ({
	type: GET_DATA_FAILURE,
	payload: {
		key, 
		message
	}
});

export const EXAM_FLOW_URL = '/api/data/ExaminationAnalysisExamFlow';
export const EXAM_SOURCE_URL = '/api/data/ExaminationAnalysisExamFlowSource';

export const getExamFlowData = (url, key, params) => (
	create(url,
		getDataRequest.bind(null, key), 
		getDataSuccess.bind(null, key), 
		getDataFailure.bind(null, key), 
		params)
);
